﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

using System.IO;

namespace SteamMoverWPF
{
    /// <summary>
    /// Interaction logic for DestinationWindow.xaml
    /// </summary>
    public partial class DestinationWindow : Window
    {
        public Game selectedGame;
        public String selectedLocation;

        private String[] _alternateLocations;

        public DestinationWindow(Game sGame)
        {
            InitializeComponent();

            _alternateLocations = new String[0];
            selectedGame = sGame;

            txtName.Text = selectedGame.Name;
            txtMainLocation.Text = selectedGame.MainLocation.FullName;
            if (selectedGame.AlternateLocation != null)
                txtAlternateLocation.Text = selectedGame.AlternateLocation.FullName;

            SetDestinations();
        }

        public void SetAlternateLocations(IEnumerable<String> AlternateLocations)
        {
            _alternateLocations = AlternateLocations.ToArray();

            SetDestinations();
        }

        public void SetDestinations()
        {
            drpDestination.Items.Clear();

            if (selectedGame.AlternateLocation != null)
                drpDestination.Items.Add(selectedGame.MainLocation.Parent.FullName);

            foreach (String l in _alternateLocations)
                if ( selectedGame.AlternateLocation == null || !selectedGame.AlternateLocation.FullName.Contains(l))
                    drpDestination.Items.Add(l);
        }

        private void drpDestination_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            selectedLocation = drpDestination.SelectedValue.ToString();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DialogResult = !String.IsNullOrEmpty(selectedLocation);
        }
    }
}
